package com.ttbj.product.api;

import java.util.List;

import com.ttbj.exception.WebException;
import com.ttbj.product.bean.dto.CargoDto;
import com.ttbj.product.bean.dto.OrderDto;
import com.ttbj.product.bean.dto.OwnerDto;
import com.ttbj.product.bean.dto.QRCodeOrderDto;
import com.ttbj.product.bean.dto.UserDto;

public interface OrderFacade {

	/**
	 * 生成搬家订单
	 * 
	 * @param sender
	 * @param reciver
	 * @throws Exception
	 */
	void createMoveOrder(OwnerDto sender, OwnerDto reciver, String openId, OrderDto orderDto) throws Exception;

	/**
	 * 生成短运订单
	 * 
	 * @param openId
	 * @param orderDto
	 * @param cargo
	 * @return
	 */
	OrderDto createCarriageOrder(String openId, OrderDto orderDto, CargoDto cargo);

	/**
	 * 根据订单id查询订单信息
	 * 
	 * @param orderId
	 * @return
	 */
	OrderDto queryOrder(Long orderId);

	/**
	 * 更新订单
	 * 根据订单id修改订单信息
	 * @param orderDto
	 * @throws Exception 
	 */
	void updateOrder(OrderDto orderDto) throws Exception;
	
	
	/**
	 * 根据订单id只修改订单状态
	 * @param orderId
	 * @param stateFlag
	 * @throws Exception 
	 */
	default void updateState(Long orderId, Integer stateFlag) throws Exception {
		OrderDto order = new OrderDto(orderId);
		order.setOrderState(stateFlag);
		updateOrder(order);
	}


	/**
	 * 所有订单查询（繁琐）
	 * 
	 * @param openId
	 * @return
	 * @throws Exception
	 */
	List<OrderDto> orderAll(UserDto userDto);

	/**
	 * 所有订单查询（简单）
	 * 
	 * @param openId
	 * @return
	 */
	List<OrderDto> simpleOrderAll(UserDto userDto);
	
	/**
	 * 订单详情
	 * 
	 * @param orderDto
	 * @param flag
	 *            0包含 货物信息和司机信息 1只包含寄件人和收件人信息
	 * @return
	 * @throws Exception
	 */
	OrderDto orderDetail(Long orderId, Integer flag) throws Exception;

	/**
	 * 订单详情(简单)
	 * 包含寄件人和收件人信息
	 * @param orderId
	 * @return
	 * @throws Exception
	 */
	default OrderDto simpleDetailOrder(Long orderId) throws Exception {
		return orderDetail(orderId, 1);
	}

	
	/**
	 * 订单详情(复杂)
	 * 包含寄件人和收件人信息
	 * 包含 货物信息和司机信息
	 * @param orderId
	 * @return
	 * @throws Exception
	 */
	default OrderDto complexDetailOrder(Long orderId) throws Exception {
		return orderDetail(orderId, 0);
	}
	
	
	/**
	 * 订单二维码生成
	 * 
	 * @throws Exception
	 */
	String newOrderCode(OrderDto orderDto) throws Exception;
	
	/**
	 * 订单二维码路径获取和订单的基本信息
	 * @param orderId
	 * @return
	 */
	QRCodeOrderDto getOrderCode(Long orderId) throws Exception;

	/**
	 * 获取二维码中订单的基本信息
	 * @param qr 
	 * 			二维码的内容由前台传递
	 * @return
	 * @throws Exception
	 */
	QRCodeOrderDto getOrderCodeInfo(String qr) throws Exception;

	/**
	 * 是否已支付
	 * @param orderId
	 * @return 
	 * @return
	 * @throws WebException 
	 * @throws Exception 
	 */
	 void isPay(String orderId) throws  Exception;

	 /**
	  * 退单
	  * @param orderId
	  */
	void orderRefund(Long orderId) throws  Exception;

}
